package com.tanhua.server.controller;

import com.tanhua.dto.RecommendUserDto;
import com.tanhua.server.service.TanhuaService;
import com.tanhua.vo.NearUserVo;
import com.tanhua.vo.PageResult;
import com.tanhua.vo.TodayBest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@Slf4j
@RestController
@RequestMapping("/tanhua")
public class TanhuaController {
    @Autowired
    private TanhuaService tanhuaService;

    /**
     * 推荐今日佳人
     *
     * @return
     */
    @GetMapping("/todayBest")
    public ResponseEntity todayBest() {
        log.info("今日佳人请求了");
        TodayBest vo = tanhuaService.RecommendTodayBest();
        return ResponseEntity.ok(vo);
    }

    /**
     * 佳人推荐列表
     *
     * @return
     */
    @GetMapping("/recommendation")
    public ResponseEntity recommendation(RecommendUserDto recommendUserDto) {
        log.info("佳人推荐列表执行了");
        PageResult pageResult = tanhuaService.recommendation(recommendUserDto);

        return ResponseEntity.ok(pageResult);
    }


    /**
     * 获取佳人信息
     *
     * @param id
     * @return
     */
    @GetMapping("/{id}/personalInfo")
    public ResponseEntity personInfo(@PathVariable("id") Long id) {
        TodayBest todayBest = tanhuaService.personInfo(id);

        return ResponseEntity.ok(todayBest);
    }

    /**
     * 查询陌生人问题
     *
     * @param userId
     * @return
     */
    @GetMapping("/strangerQuestions")
    public ResponseEntity strangerQuestions(@RequestParam Long userId) {
        String question = tanhuaService.strangerQuestions(userId);

        return ResponseEntity.ok(question);
    }

    /**
     * 回复陌生人问题
     *
     * @param map
     * @return
     */
    @PostMapping("/strangerQuestions")
    public ResponseEntity answerQuestion(@RequestBody Map map) {
        //将前端传入的Integer类型的userId转为Long类型
        String obj = map.get("userId").toString();
        Long userId = Long.valueOf(obj);
        String reply = (String) map.get("reply");

        tanhuaService.answerQuestion(userId, reply);

        return ResponseEntity.ok(null);
    }

    /**
     * 返回探花-左滑右滑列表
     *
     * @return
     */
    @GetMapping("/cards")
    public ResponseEntity cards() {
        List<TodayBest> list = tanhuaService.cards();
        return ResponseEntity.ok(list);
    }

    /**
     * 探花-喜欢
     *
     * @param id
     * @return
     */
    @GetMapping("/{id}/love")
    public ResponseEntity love(@PathVariable("id") Long id) {
        tanhuaService.love(id);
        return ResponseEntity.ok(null);
    }

    /**
     * 探花-不喜欢
     * @param id
     * @return
     */
    @GetMapping("/{id}/unlove")
    public ResponseEntity unove(@PathVariable("id") Long id) {
        tanhuaService.unLove(id);
        return ResponseEntity.ok(null);
    }


    /**
     * 搜附近
     * @param gender
     * @param distance
     * @return
     */
    @GetMapping("/search")
    public ResponseEntity search(String gender,
                                 @RequestParam(defaultValue = "2000") String distance) {
        List<NearUserVo> list = tanhuaService.search(gender, distance);
        return ResponseEntity.ok(list);
    }

}
